using MicroMsg.Manager;
using MicroMsg.Plugin.Sns.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class MasterPageGroupItem : SnsHttpImgCtrlBase
	{
		private string[] strUrlList;
		private List<Image> imgList;
		private MasterImgGroup mGroup;
		internal Grid LayoutRoot;
		internal DynamicTextBlock GroupNameTxt;
		internal Grid PicGrid;
		private bool _contentLoaded;
		public MasterPageGroupItem()
		{
			this.InitializeComponent();
		}
		protected override void ObjectCome(object object_0)
		{
			if (object_0 != null && object_0 is snsMediaDownloadInfo)
			{
				snsMediaDownloadInfo snsMediaDownloadInfo = object_0 as snsMediaDownloadInfo;
				if (snsMediaDownloadInfo.object_0 != null && snsMediaDownloadInfo.object_0 is BitmapImage)
				{
					for (int i = 0; i < this.imgList.get_Count(); i++)
					{
						if (this.strUrlList[i] == snsMediaDownloadInfo.string_0 && this.imgList.get_Item(i).get_Source() == null)
						{
							this.imgList.get_Item(i).set_Source(snsMediaDownloadInfo.object_0 as BitmapImage);
						}
					}
				}
				return;
			}
		}
		private void ReArrangeUI(int count)
		{
			this.PicGrid.set_Height((double)(115 * ((count + 2) / 3) - 2));
			if (this.imgList == null)
			{
				this.imgList = new List<Image>();
			}
			if (count < this.imgList.get_Count())
			{
				for (int i = this.imgList.get_Count() - 1; i >= count; i--)
				{
					this.PicGrid.get_Children().RemoveAt(i);
					this.imgList.RemoveAt(i);
				}
				return;
			}
			if (count > this.imgList.get_Count())
			{
				for (int j = this.imgList.get_Count(); j < count; j++)
				{
					MasterPagePicItem masterPagePicItem = new MasterPagePicItem();
					masterPagePicItem.set_Margin(new Thickness((double)(j % 3 * 115), (double)(j / 3 * 115), 0.0, 0.0));
					this.PicGrid.get_Children().Add(masterPagePicItem);
					masterPagePicItem.ItemClick += new MasterPagePicItem.ListItemClick(this.item_Click);
					this.imgList.Add(masterPagePicItem.imgContent);
				}
			}
		}
		private void item_Click(object sender, object object_0)
		{
			BasePage rootPage = ToolFunction.GetRootPage();
			if (rootPage is BackgroundMasterPage)
			{
				BackgroundMasterPage backgroundMasterPage = rootPage as BackgroundMasterPage;
				MasterPagePicItem masterPagePicItem = sender as MasterPagePicItem;
				int num = (int)(masterPagePicItem.get_Margin().get_Top() / 113.0) * 3 + (int)(masterPagePicItem.get_Margin().get_Left() / 113.0);
				int num2 = -1;
				List<TloMedia> list = new List<TloMedia>();
				int num3 = 0;
				for (int i = 0; i < backgroundMasterPage.masterAlbum.imgGroupList.get_Count(); i++)
				{
					for (int j = 0; j < backgroundMasterPage.masterAlbum.imgGroupList.get_Item(i).imgList.get_Count(); j++)
					{
						list.Add(backgroundMasterPage.masterAlbum.imgGroupList.get_Item(i).imgList.get_Item(j));
						if (j == num && this.mGroup.groupName == backgroundMasterPage.masterAlbum.imgGroupList.get_Item(i).groupName)
						{
							num2 = num3;
						}
						if (num2 == -1)
						{
							num3++;
						}
					}
				}
				TimeLineObject timeLineObject = new TimeLineObject();
				timeLineObject.content = new ContentObject
				{
					mediaList = list
				};
				List<TimeLineObject> list2 = new List<TimeLineObject>();
				list2.Add(timeLineObject);
				object[] object_ = new object[]
				{
					list2,
					num2
				};
				ToolFunction.GotoPageForUserControl("/Source/Plugin/Sns/Common/UI/AlbumCover/MasterPageSlideView.xaml", object_, false);
			}
		}
		public void SetContent(MasterImgGroup item)
		{
			this.mGroup = item;
			this.GroupNameTxt.Text = item.groupName;
			this.strUrlList = new string[item.imgList.get_Count()];
			this.ReArrangeUI(item.imgList.get_Count());
			base.get_Dispatcher().BeginInvoke(delegate
			{
				for (int i = 0; i < item.imgList.get_Count(); i++)
				{
					this.strUrlList[i] = item.imgList.get_Item(i).strThumb;
					snsMediaDownloadInfo objReqInfo = new snsMediaDownloadInfo
					{
						string_0 = item.imgList.get_Item(i).strThumb,
						urlType = (SnsUrlType)item.imgList.get_Item(i).nUrlType,
						snsObjID = item.imgList.get_Item(i).nID,
						priority = SnsPriority.LOW
					};
					this.StartRequest(objReqInfo, true);
				}
			});
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Common/UI/AlbumCover/MasterPageGroupItem.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.GroupNameTxt = (DynamicTextBlock)base.FindName("GroupNameTxt");
			this.PicGrid = (Grid)base.FindName("PicGrid");
		}
	}
}
